//
//  SearchDetailTableViewController.swift
//  Wmsmobile
//
//  Created by wangshuning on 16/8/22.
//  Copyright © 2016年 www.hd123.com. All rights reserved.
//

import UIKit
//托盘库存   在使用该控制器
class SearchDetailTableViewController: UITableViewController {
    
    //MARK: - property
    var info: [String : String]?
    let dataArray = ["货品代码","货品名称","货品规格","规格","件数","保质期","生产日期"]
    
    init(){
        super.init(style: UITableViewStyle.plain)
    }
    convenience init(info: [String : String]){
        self.init()
        self.info = info
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.tableView.register(binDetailCell.self, forCellReuseIdentifier: "binDetailCell")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source

    override func numberOfSections(in tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 1
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return self.dataArray.count
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "binDetailCell") as! binDetailCell
        let title =  dataArray[(indexPath as NSIndexPath).row]
        var info = ["title" : title]
        switch title {
        case "货品代码":
            info.updateValue(self.info!["货品代码"] ?? "", forKey: "detail")
            info.updateValue("calendar-2", forKey: "icon")
            //        case "托盘":
            //            info.updateValue(self.info!["托盘号"] ?? "", forKey: "detail")
            //        case "重量":
        //            info.updateValue(self.info!["单品重量"] ?? "", forKey: "detail")
        case "保质期":
            let string = String(self.info!["保质期"] ?? "0")
            let array = string?.components(separatedBy: " ")
            let stringFinal = array!.first?.replacingOccurrences(of: "/", with: "-")
            info.updateValue(stringFinal ?? "", forKey: "detail")
        case "生产日期":
            let string = String(self.info!["生产日期"] ?? "0")
            let array = string?.components(separatedBy: " ")
            let stringFinal = array!.first?.replacingOccurrences(of: "/", with: "-")
            info.updateValue(stringFinal ?? "", forKey: "detail")
        default:
            info.updateValue(self.info![title] ?? "", forKey: "detail")
        }
        cell.info = info
        return cell
    }
}

